﻿using System.Collections;
using System.Collections.Generic;
using LuaFramework;

/// <summary>
/// 数据管理
/// </summary>

    public class LoginManger : Singleton<LoginManger>
    {
        private string account;

        public string Account
        {
            get { return account; }
            set { account = value; }
        }

        private string password;

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        //是否登录成功
        private bool isLoginSuccess = false;

        public bool IsLoginSuccess
        {
            get { return isLoginSuccess; }
            set
            {

                if (isLoginSuccess != value)
                {
                    isLoginSuccess = value;
                    EventDispatcher.TriggerEvent<bool>(EventKey.OnPlayerLoginSuccess, isLoginSuccess);
                }
            }
        }

        /// <summary>
        ///玩家注册账户的信息
        /// </summary>
        private UserAccountInfo registAccountInfo;

        public UserAccountInfo RegistAccountInfo
        {
            get { return registAccountInfo; }
            set { registAccountInfo = value; }
        }

        /// <summary>
        ///玩家注册账户成功后的信息
        /// </summary>
        private UserAccountInfo registSuccessAccountInfo;

        public UserAccountInfo RegistSuccessAccountInfo
        {
            get { return registSuccessAccountInfo; }
            set
            {
                if (registSuccessAccountInfo != value)
                {

                    registSuccessAccountInfo = value;

                    EventDispatcher.TriggerEvent<UserAccountInfo>(EventKey.OnPlayerRegistSuccess,
                        registSuccessAccountInfo);
                }

            }
        }

        #region 注册

        /// <summary>
        /// 发送给服务器 注册一个账户
        /// </summary>
        public void SendToServerRegistRequst()
        {
            LoginNetHandler.instance.SentToServerRegistAccountRequest(1000, RegistAccountInfo);
        }

        /// <summary>
        /// 服务器 返回注册结果
        /// </summary>
        public void OnReceiveServerBackRegistAccountResponse(UserAccountInfo info)
        {
            RegistSuccessAccountInfo = info;
        }

        #endregion


        #region 登录

        /// <summary>
        /// 发送给服务器 登录一个账户
        /// </summary>
        public void SendToServerLoginRequst()
        {
            //UserAccountInfo userAccountInfo = new UserAccountInfo() {account = Account, password = Password};
            UserAccountInfo userAccountInfo = new UserAccountInfo();
            userAccountInfo.account = Account;
            userAccountInfo.password = Password;
            LoginNetHandler.instance.SentToServerLoginAccountRequest(1000, userAccountInfo);
        }

        /// <summary>
        /// 服务器 返回登录结果
        /// </summary>
        public void OnReceiveServerBackLoginAccountResponse(bool info)
        {
            IsLoginSuccess = info;
        }

        #endregion

    }

    

public class UserAccountInfo
{
    //账户
    public string account;
    //密码
    public string password;
}